<style scoped>
.line{
    height: 0px;
    border-bottom: 1px solid #ddd;
    margin-top: 15px;
    margin-bottom: 15px;
}
.pl20{
    padding-left: 20px;
}
</style>
<style>

</style>

<template>
  <div class="wrap">
        <product-title></product-title>
        <div class="pl20">  
            <!-- ref="proform" :rules="ruleValidate"          -->
            <Row>
                <Col span="8">               
                    <Form :model="achievement" ref="achievement" :rules="ruleValidate" :label-width="120">
                        
                        <Form-item label="保单号：" prop="policy_no" required>
                            <Input v-model="achievement.policy_no" disabled placeholder="请输入保单编号"></Input>                            
                        </Form-item>                    
                        <Form-item label="代理人：" prop="agent_name" >
                            <Input v-model="achievement.agent_name" disabled placeholder="请输入代理人"></Input>
                        </Form-item>
                        <Form-item label="投保人：">
                            <Input v-model="achievement.au_name" disabled placeholder="请输入投保人"></Input>
                        </Form-item>
                        <Form-item label="产品：" required>
                            <Input v-model="achievement.pname" disabled placeholder="请输入投保人"></Input>
                        </Form-item>
                        <Form-item label="交费时间：" prop="pay_time_date"  required>
                            <DatePicker type="date" v-model="achievement.pay_time_date" @on-change="timechange($event)" placeholder="选择交费日期" ></DatePicker>
                        </Form-item>
                        <Form-item label="保险年度：" prop="pay_num" required>
                            <Input v-model="achievement.pay_num" placeholder="请输入保险年度"></Input>
                        </Form-item>
                        <Form-item label="保险期间：" prop="period" required>                           
                            <Input v-model="achievement.period" disabled placeholder="请输入保险期间"></Input>
                        </Form-item>
                        <Form-item label="交费期间：" prop="pay_period" required>                            
                            <Input v-model="achievement.pay_period" disabled placeholder="请输入交费期间"></Input>
                        </Form-item>
                        <Form-item label="保费：" prop="premium" required>
                            <Input v-model="achievement.premium" disabled placeholder="请输入保费"></Input>
                        </Form-item>
                        <FormItem>
                            <Button type="primary" @click="sendAll()">提交</Button>
                            <Button type="ghost" @click="cancel()" style="margin-left: 8px">取消</Button>
                        </FormItem>                  
                    </Form>
                </Col>
            </Row>                
        </div>

  </div>
</template>
<script>
import productTitle from '../../components/productTitle'
import { getProListAll } from '../../api/product_v2'
import { creatAgreement } from '../../api/agreement'
import { searchPolicy , getDetailById } from '../../api/policyb'
import { getCustomerAllById } from '../../api/customer'
import {  updateAchi , getDetail } from '../../api/achievement'
import { getAllEmployee } from '../../api/employee' 
export default {
    data () {
        return {
            achievement: {
                au_id:'',
                au_name:'',
                pid:'',
                pay_time:''
            },
            uidList:[
            ],
            auidList:{},
            prolist:[],
            periodList:[],
            pay_periodList:[],
            insertModal:false,
            modalSearch:'',
            proparams:[],
            period:[

            ],
            pay_period:[

            ],
            org:[

            ],
            ruleValidate:{
                policy_no: [
                    { required: true, message: '保单号不能为空', trigger: 'blur,change' }
                ],
                agent_name: [
                    { required: true, message: '代理人不能为空', trigger: 'blur,change' }
                ],
                pid: [
                    { required: true, message: '产品不能为空', trigger: 'change' }
                ],
                pay_time_date:[
                    { required: true, type: 'date', message: '交费时间不能为空', trigger: 'change' }
                ],
                pay_num:[
                    { required: true, message: '保险年度不能为空', trigger: 'blur,change' }
                ],
            },
            columns_customer:[
                {
                    title: '保单号',
                    key: 'num',
                    align: 'center'
                },
                {
                    title: '公司名称',
                    key: 'cname',
                    align: 'center'
                },
                {
                    title: '操作',
                    key: 'action',
                    align: 'center',
                    render: (h, params) => {
                        return h('div', [
                            h('Button', {
                                props: {
                                    type: 'primary',
                                    size: 'small'
                                },
                                on:{
                                    click:() => {
                                        this.getpolicy(params.row.id,params.row.num);
                                    }
                                }
                            }, '添加'),
                        ]);
                    }
                }
            ],
            data_customer:[
                
            ],
            tempnum:''
        }
    },
    components: {
        productTitle,
        
    },
    mounted () {

    },
    created () {
        this.getdetail()
    },
    watch: {
        '$route' (to, from) {
      // 对路由变化作出响应...
        
        }
    },
    methods: {
        getdetail(){
            let _params ={
               id : this.$route.params.id
            }
            new Promise((resolve, reject) => {
                getDetail(_params).then(response => {
                    console.log(response.data)
                    if(response.data.err == 0){
                        // this.data_customer = response.data.data
                        // let _id = response.data.data[0].id
                        // this.getpolicy(_id,_params.num)
                        // this.achievement.policy_no = response.data.data.policy_no
                        // this.achievement.agent_name = response.data.data.agent_name
                        // this.achievement.uid = response.data.data.uid
                        // this.achievement.au_name = response.data.data.au_name
                        // this.achievement.pname =  response.data.data.pname
                        // this.achievement.pay_period =  response.data.data.pay_period
                        // this.achievement.period =  response.data.data.period
                        // this.achievement.premium = response.data.data.premium
                        this.achievement = response.data.data
                        this.achievement.pay_time_date = response.data.data.pay_time
                    } else {
                       this.$Message.error(response.data.info);
                    }                       
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },
        timechange(date){
            this.achievement.pay_time = date
        },
        pidchange(value){
            this.achievement.pay_period = this.proparams[value].payPeriod 
            this.achievement.period = this.proparams[value].insurancePeriod
            this.achievement.premium = this.proparams[value].premium 
            this.achievement.pid = this.proparams[value].insuranceId 
            this.achievement.pname = this.proparams[value].insuranceName  
        },
        //打开模态框
        openModal(){
            this.insertModal = true
        },

        sendAll(name) {
            this.$refs['achievement'].validate((valid) => {
                if (valid) {
                    new Promise((resolve, reject) => {
                        updateAchi(this.achievement).then(response => {
                            if(response.data.err == 0){
                                this.$Message.success(response.data.info);
                                this.$router.push({'name':'achievement_index'});   
                            } else {
                                this.$Message.error(response.data.info);
                            }                       
                            resolve();
                        }).catch(error => {
                            reject(error);
                        });
                    });
                } else {
                    this.$Message.error('表单验证失败!');
                }
            })
        },
        cancel() {            
            this.$router.push({'name':'achievement_index',meta:{keepAlive:true}});      
        }
    }
}
</script>

